package cn.snoworld.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.snoworld.dto.CommonResult;
import cn.snoworld.entity.Blogroll;
import cn.snoworld.service.BlogrollService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "友情链接接口")
@RequestMapping("/blog/blogroll")
public class BlogrollController {
    @Autowired
    private BlogrollService blogrollService;

    @ApiOperation("获取所有友情链接信息")
    @GetMapping
    public CommonResult getAll() {
        return CommonResult.OK(blogrollService.list());
    }

    @ApiOperation("根据id获取友情链接信息")
    @GetMapping("{id}")
    public CommonResult getOneById(@PathVariable Integer id) {
        return CommonResult.OK(blogrollService.getById(id));
    }

    @ApiOperation("新增一个友情链接")
    @PostMapping
    public CommonResult addOne(@RequestBody Blogroll blogroll) {
        blogrollService.save(blogroll);
        return CommonResult.OK();
    }

    @ApiOperation("修改一个友情链接")
    @PutMapping
    public CommonResult modifyOneById(@RequestBody Blogroll blogroll) {
        blogrollService.updateById(blogroll);
        return CommonResult.OK();
    }

    @ApiOperation("删除一个友情链接")
    @DeleteMapping
    public CommonResult removeOneById(@RequestBody Blogroll blogroll) {
        blogrollService.removeById(blogroll.getId());
        return CommonResult.OK();
    }

    @ApiOperation("删除一个友情链接")
    @DeleteMapping("{id}")
    public CommonResult removeOneById(@PathVariable Integer id) {
        blogrollService.removeById(id);
        return CommonResult.OK();
    }
}
